using UnityEngine;
using System.Collections;

public class TestTrack : MonoBehaviour {

	// Use this for initialization
	void Start () {
		
		//We'll generate 2 track sections
		SplineControlPoint[] track1 = new SplineControlPoint[2];
		SplineControlPoint[] track2 = new SplineControlPoint[2];
		
		//Generate the spline control points for track section 1
		track1[0] = new SplineControlPoint(new Vector3(0, 50, 0), new Vector3(1,0,0), new float[] {50, 50});
		track1[1] = new SplineControlPoint(new Vector3(100, 0, 0), new Vector3(1,0,0), new float[] {50, 50});
		
		//Generate a track from these spline control points
		Spline3D[] trackSections1 = TrackFactory.genTrack(track1, TrackFactory.rail);
		
		//Add terminals to trackSections1
		trackSections1[0].type = TrackFactory.terminal;
		trackSections1[trackSections1.Length-1].type = TrackFactory.terminal;
		
		//Generate the spline control points for track section 2, using the end point of one section of trackSections1 as a starting point
		track2[0] = trackSections1[3].endSplineControlPoint;
		track2[0].weights = new float[] {50,50};
		track2[1] = new SplineControlPoint(new Vector3(100, 0, -100), new Vector3(1,0,0), new float[] {50, 50});
		
		//Generate a track from these spline control points
		Spline3D[] trackSections2 = TrackFactory.genTrack(track2, TrackFactory.rail);
		
		//Adjust the layers of the track sections just after the switch so the cart can go the right way
		trackSections1[4].layer = LayerMask.NameToLayer("Tracks going left");
		trackSections2[0].layer = LayerMask.NameToLayer("Tracks going right");
		
		//Convert the track sections into meshes
		TrackFactory.genRails(trackSections1);
		TrackFactory.genRails(trackSections2);
	}
}
